
#pragma once
 
#include <iostream>
#include <string>
#include <functional>
#include <pthread.h>
#include "log.hpp"

class Task
{
public:
    using callback_t = std::function<void (int, std::string, uint16_t)>;
public:
    Task():sock_(-1), port_(-1)
    {}
    Task(int sock, std::string ip, uint16_t port, callback_t func)
        : sock_(sock), ip_(ip), port_(port), func_(func)
    {}

    void operator() ()
    {
        logMessage(DEBUG, "线程ID[%p]处理%s:%d的请求 开始了...",\
            pthread_self(), ip_.c_str(), port_);

        func_(sock_, ip_, port_);

        logMessage(DEBUG, "线程ID[%p]处理%s:%d的请求 结束了...",\
            pthread_self(), ip_.c_str(), port_);
    }

    ~Task()
    {}
private:
    int sock_;
    uint16_t port_;
    std::string ip_;
    callback_t func_;
};